package com.sky.controller.user;

import com.sky.controller.BaseController;
import com.sky.entity.SetmealDishEntity;
import com.sky.entity.SetmealEntity;
import com.sky.enumeration.SetmealStatusEnum;
import com.sky.result.Result;
import com.sky.service.SetmealDIshService;
import com.sky.service.SetmealService;
import com.sky.vo.SetmealDishWithUserVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "C端套餐模块")
@RestController
@RequestMapping("/user/setmeal")
@Slf4j
public class SetmealController extends BaseController {

    @Autowired
    private SetmealService setmealService;

    @Autowired
    private SetmealDIshService setmealDIshService;

    @ApiOperation("根据分类ID查询套餐列表")
    @GetMapping("/list")
    @Cacheable(cacheNames = "setmealCache", key = "#categoryId")
    public Result list(@RequestParam Integer categoryId) {
        log.info("根据分类ID查询套餐列表 =>{}", categoryId);
        SetmealEntity setmealEntity = new SetmealEntity();
        setmealEntity.setCategoryId(Long.valueOf(categoryId));
        setmealEntity.setStatus(SetmealStatusEnum.Enable);
        List<SetmealEntity> list = setmealService.list(setmealEntity);
        return Result.success(list);
    }

    @GetMapping("/dish/{id}")
    @ApiOperation("根据套餐ID查询对应的菜品列表")
    public Result dish(@PathVariable("id") Integer setmealId) {
        log.info("根基套餐ID查询对应的菜品列表 =>{}", setmealId);

        List<SetmealDishWithUserVO> list = setmealDIshService.getBySetmealIdWithUser(setmealId);

        return Result.success(list);
    }
}
